package asia.lics.web.controller.testPaper;


import asia.lics.common.annotation.Log;
import asia.lics.common.core.controller.BaseController;
import asia.lics.common.core.domain.AjaxResult;
import asia.lics.common.core.page.TableDataInfo;
import asia.lics.common.enums.BusinessType;
import asia.lics.common.utils.poi.ExcelUtil;
import asia.lics.system.domain.CTestPaper;
import asia.lics.system.domain.vo.TestPaperImport;
import asia.lics.system.service.ICTestPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 试卷管理Controller
 *
 * @author ss-tutor
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/system/paper")
public class CTestPaperController extends BaseController {
    @Autowired
    private ICTestPaperService cTestPaperService;

    /**
     * 查询试卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(CTestPaper cTestPaper) {
        startPage();
        List<CTestPaper> list = cTestPaperService.selectCTestPaperList(cTestPaper);
        return getDataTable(list);
    }

    /**
     * 导出试卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:paper:export')")
    @Log(title = "试卷管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CTestPaper cTestPaper) {
        List<CTestPaper> list = cTestPaperService.selectCTestPaperList(cTestPaper);
        ExcelUtil<CTestPaper> util = new ExcelUtil<CTestPaper>(CTestPaper.class);
        util.exportExcel(response, list, "试卷管理数据");
    }

    /**
     * 获取试卷管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:paper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cTestPaperService.selectCTestPaperById(id));
    }

    /**
     * 新增试卷管理
     */
    @PreAuthorize("@ss.hasPermi('system:paper:add')")
    @Log(title = "试卷管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CTestPaper cTestPaper) {
        return toAjax(cTestPaperService.insertCTestPaper(cTestPaper));
    }

    /**
     * 修改试卷管理
     */
    @PreAuthorize("@ss.hasPermi('system:paper:edit')")
    @Log(title = "试卷管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CTestPaper cTestPaper) {
        return toAjax(cTestPaperService.updateCTestPaper(cTestPaper));
    }

    /**
     * 删除试卷管理
     */
    @PreAuthorize("@ss.hasPermi('system:paper:remove')")
    @Log(title = "试卷管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cTestPaperService.deleteCTestPaperByIds(ids));
    }


    /**
     * 导入
     */
    @PreAuthorize("@ss.hasPermi('system:paper:import')")
    @Log(title = "试卷管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestBody TestPaperImport testPaperImport) {
        cTestPaperService.importData(testPaperImport);
        return AjaxResult.success();
    }
}
